import os
from pathlib import Path


def get_self_ip():
    '''
    获取本机ip
    '''
    import socket
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(('8.8.8.8', 80))
        ip = s.getsockname()[0]
    finally:
        s.close()
    return ip


root_path = Path(__file__).parent
root_path = str(root_path)+'/'
#  host = 'localhost'
host = get_self_ip()
port = 12345
debug = True
VIM_URl_PREX = '/vim'


def start_server():
    from lly.server.main import app
    import uvicorn
    print(f"{host} {port}")
    uvicorn.run(app, host=host, port=port, reload=False)
    #  os.system(f"uvicorn lly.server.main:app --reload --port {port} --host {host}")


def generate_vim_url(file_path):
    return f"http://{host}:{port}{VIM_URl_PREX}/{file_path}"
